package io.gitee.zhangbinhub.acp.boot.component

import io.gitee.zhangbinhub.acp.boot.constant.AcpCoreConstant
import io.gitee.zhangbinhub.acp.boot.tools.ReactiveRequestContextHolder
import org.springframework.core.annotation.Order
import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebFilter
import org.springframework.web.server.WebFilterChain
import reactor.core.publisher.Mono

@Order(AcpCoreConstant.CORS_FILTER_ORDER + 10)
class ReactiveWebFilter : WebFilter {
    override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> =
        chain.filter(exchange)
            .contextWrite { ctx ->
                ctx.put(ReactiveRequestContextHolder.CONTEXT_KEY, exchange)
            }
}